package com.iscale.system.security.ip;

import com.iscale.system.exception.ForbiddenIpException;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * ip拦截前置拦截器
 */
@Aspect
@Component
@Order(1) //order值越小越先执行
public class ForbiddenIpAOP {

    private static Logger log = LoggerFactory.getLogger(ForbiddenIpAOP.class);



    @Before("@within(org.springframework.web.bind.annotation.RequestMapping)")
    public void forbiddenIp() throws ForbiddenIpException {
//        if ("true".equals(systemService.selectDataItemByKey(SystemConstant.ipForbidden))) {
//            log.debug("open ip intercepter : {}", true);
//            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
//            String remoteAddr = request.getRemoteAddr();
//            if (systemService.isForbiddenIp(remoteAddr)) {
//                log.error("this {}  ip is  forbidden ", remoteAddr);
//                throw new ForbiddenIpException(ResponseCode.forbidden_ip.getMsg());
//            }
//        }
    }
}
